import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:common_utils/common_utils.dart';

class GoodsOrderInfoItem extends StatelessWidget {

  final String title;
  final String value;
  final bool showCopy;
  final bool valueBold;
  final Color? titleColor;
  final String? color;

  GoodsOrderInfoItem({
    required this.title,
    required this.value,
    this.showCopy = false,
    this.valueBold = false,
    this.titleColor,
    this.color
  });
  
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: TextStyle(
              // color: titleColor ?? textSubtitleColor,
              color: TextUtil.isEmpty(color) ? titleColor ?? textSubtitleColor : hexToColor(color!),
              fontSize: 14.sp
            ),
          ),
          SizedBox(width: 12.w),
          Expanded(child: Row(
            
            children: [
              Expanded(child: Text(
                '$value',
                textAlign: TextAlign.end,
                style: TextStyle(
                  color: TextUtil.isEmpty(color) ? textBlackColor : hexToColor(color!),
                  fontSize: 14.sp,
                  fontWeight: valueBold ? FontWeight.bold : FontWeight.normal
                ),
              )),
              showCopy ? Container(
                margin: EdgeInsets.only(left: 10.w),
                child: InkWellUtil.shakeProofInkWell(Text(
                  '复制',
                  style: TextStyle(
                    color: mainTextColor,
                    fontSize: 12.sp
                  ),
                ), () {
                  Clipboard.setData(ClipboardData(text: value));
                  EasyLoading.showToast('复制成功');
                }),
              ) : Container()
            ],
          ))
        ],
      ),
    );
  }

  Color hexToColor(String code) {
    return new Color(int.parse('#$code'.substring(1, 7), radix: 16) + 0xFF000000);
  }
}